package com.derbysoft.synxisadapter.dswitch2.service.impl;

import com.derbysoft.remote.dswitch.core.GenericRQ;
import com.derbysoft.remote.dswitch.core.GenericRS;
import com.derbysoft.remote.dswitch.generic.constants.TransactionActionType;
import com.derbysoft.remote.dswitch.hotel.dto.*;
import com.derbysoft.synxisadapter.dswitch2.service.HotelProviderService;

public class HotelProviderWebServiceImpl extends AbstractHotelProviderWebService {

    private HotelProviderService<GenericRQ<HotelAvailRQ>, GenericRS<HotelAvailRS>> hotelAvailService;

    private HotelProviderService<GenericRQ<HotelReservationRQ>, GenericRS<HotelReservationRS>> hotelPreviewService;

    private HotelProviderService<GenericRQ<HotelReservationRQ>, GenericRS<HotelReservationRS>> hotelReservationService;

    private HotelProviderService<GenericRQ<CancelRQ>, GenericRS<CancelRS>> cancelService;

    private HotelProviderService<GenericRQ<HotelMultiAvailRQ>, GenericRS<HotelMultiAvailRS>> hotelMultiAvailService;

    @Override
    public GenericRS<HotelMultiAvailRS> getMultiAvailability(GenericRQ<HotelMultiAvailRQ> rq) {
        return hotelMultiAvailService.invoke(rq);
    }

    @Override
    public GenericRS<HotelAvailRS> getAvailability(GenericRQ<HotelAvailRQ> rq) {
        return hotelAvailService.invoke(rq);
    }

    @Override
    public GenericRS<HotelReservationRS> makeReservation(final GenericRQ<HotelReservationRQ> rq) {
        if (rq.getPayload().getResActionType() == TransactionActionType.INITIATE) {
            return hotelPreviewService.invoke(rq);
        }
        return hotelReservationService.invoke(rq);
    }

    @Override
    public GenericRS<CancelRS> cancelReservation(GenericRQ<CancelRQ> rq) {
        return cancelService.invoke(rq);
    }

    public void setHotelAvailService(HotelProviderService hotelAvailService) {
        this.hotelAvailService = hotelAvailService;
    }

    public void setHotelReservationService(HotelProviderService hotelReservationService) {
        this.hotelReservationService = hotelReservationService;
    }

    public void setCancelService(HotelProviderService cancelReservationService) {
        this.cancelService = cancelReservationService;
    }

    public void setHotelMultiAvailService(HotelProviderService hotelMultiAvailService) {
        this.hotelMultiAvailService = hotelMultiAvailService;
    }

    public void setHotelPreviewService(HotelProviderService hotelPreviewService) {
        this.hotelPreviewService = hotelPreviewService;
    }
}
